import React, { Component } from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'
import RouterLink from '../router/routerLink'
export default class RouterView extends Component {
	render() {
		console.log(this.props);
		let { routes } = this.props
		return (
			<div>
				<Switch>
					{
						routes.map((item, index) => {
							if (item.from) {
								return <Redirect key={index} exact from={item.from} to={item.to} />
							}
							if (!item.from && item.to) {
								return <Redirect key={index} to={item.to} />
							}
							return <Route key={index} path={item.path} render={(router) => {
								let Com = item.component
								return <><Com {...router} /><RouterLink routes={routes} selfClassName={'active'} /></>
							}} />
						})
					}
				</Switch>
			</div>
		)
	}
}
